package com.dfd.mango.consumer.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.interceptor.RetryInterceptorBuilder;
import org.springframework.retry.interceptor.RetryOperationsInterceptor;

/**
 *  自定义重试拦截器
 *      由于使用的consul注册中心，在启动的时候会抛出一个异常A component required a bean named 'configServerRetryInterceptor' that could not be found.
 *      书中写是缺少了这个拦截器，需要手动写一个
 * @link ConfigServerInstanceProvider
 *
 */
public class RetryProvider {


    @Bean
    @ConditionalOnMissingBean(name = "configServerRetryInterceptor")
    public RetryOperationsInterceptor configServerRetryInterceptor() {
        return RetryInterceptorBuilder.stateless().backOffOptions(1000, 1.2, 5000).maxAttempts(10).build();
    }

}
